﻿using System;
using System.Collections.Generic;

namespace Opo.Perspective.Core
{
    /// <summary>
    /// Represents a service to get mail messages from a mail cache
    /// </summary>
    public class MailService : IService<Message>
    {
        private MailCache _mailCache;

        /// <summary>
        /// Initializes a new instance of the <see cref="MailService"/> class.
        /// </summary>
        /// <param name="mailCache">The mail cache.</param>
        public MailService(MailCache mailCache)
        {
            if (mailCache == null)
            {
                throw new ArgumentNullException("mailCache");
            }
            _mailCache = mailCache;
        }

        /// <summary>
        /// Adds the specified message.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <returns></returns>
        public Message Add(Message message)
        {
            return _mailCache.Add(message);
        }

        /// <summary>
        /// Gets the message specified by the id.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <returns></returns>
        public Message Get(Guid id)
        {
            return _mailCache.Get(id);
        }

        /// <summary>
        /// Gets all messages.
        /// </summary>
        /// <returns></returns>
        public IList<Message> GetAll()
        {
            return new List<Message>(_mailCache.GetAll());
        }

        /// <summary>
        /// Updates the specified message.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <returns></returns>
        public Message Update(Message message)
        {
            return _mailCache.Update(message);
        }

        /// <summary>
        /// Deletes the specified message.
        /// </summary>
        /// <param name="message">The message.</param>
        public void Delete(Message message)
        {
            _mailCache.Delete(message);
        }
    }
}
